package one.three.eight;

import edu.princeton.cs.algs4.StdIn;

public class DoublingStack<Item> {

	private Item[] a;
	private int n;

	public DoublingStack(int c) {
		a = (Item[]) new Object[c];
	}

	private void resize(int max) {
		Item[] temp = (Item[]) new Object[max];
		for (int i = 0; i < n; i++) {
			temp[i] = a[i];
		}
		a = temp;
	}

	public void push(Item item) {
		if (n == a.length)
			resize(2 * a.length);
		a[n++] = item;
	}

	public Item pop() {
		Item item = a[--n];
		a[n] = null;
		if (n > 0 && n == a.length / 4)
			resize(a.length / 2);
		return item;
	}

	public static void main(String[] args) {
		String[] a = StdIn.readAllStrings();
		//System.out.println(a.length);
		DoublingStack<String> s=new DoublingStack<String>(1);
		for(int i=0;i<a.length;i++) {
			//System.out.println(a[i]);
			s.push(a[i]);
		}
		System.out.println(s.n);
	}

}
